package leeon.mobile.server.bbscache.entity;

import java.io.Serializable;
import java.util.Date;

import leeon.mobile.BBSBrowser.models.BoardObject;
import leeon.mobile.BBSBrowser.models.DocObject;
import leeon.mobile.server.bbscache.Utils;

//一个属性较少用于放入缓存的类
public class DocMini implements Serializable {
	
	private static final long serialVersionUID = -8481146318679935370L;

	private Long id;
	
	private Long gid;
	
	private Date date;
	
	private boolean sticky;
	
	private DocMini(Long id, Long gid, Date date, boolean sticky) {
		this.id = id;
		this.gid = gid;
		this.date = date;
		this.sticky = sticky;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getGid() {
		return gid;
	}

	public void setGid(Long gid) {
		this.gid = gid;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public boolean isSticky() {
		return sticky;
	}

	public void setSticky(boolean sticky) {
		this.sticky = sticky;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		return id.equals(((DocMini)obj).id);
	}
	
	
	
	public DocObject toDocObject(BoardObject b) {
		return new DocObject(String.valueOf(id), 
				null, null, Utils.dateToString(date), 
				null, sticky, b);
	}
	
	public static DocMini toDocMini(DocObject d) {
		return new DocMini(Long.valueOf(d.getId()), 
				d.getGid()!=null?Long.valueOf(d.getGid()):null,
				Utils.stringToDate(d.getDate()), d.isSticky());
	}
	
}
